<template>
  <div class="my-container">
    <!-- 个人信息界面 -->
    <div class="header userinfo" v-if="this.user">
      <div class="base-info">
        <div class="left">
          <van-image
            class="userinfo-img"
            round
            fit="cover"
            :src="userInfo.photo"
          />
          <span class="text">{{userInfo.name}}</span>
        </div>
        <div class="right">
          <van-button
          class="editUserInfo"
          round size="mini"
          to="/myprofile"
            >编辑信息</van-button
          >
        </div>
      </div>
      <div class="status-info">
        <div class="data-item">
          <div class="conter">{{userInfo.art_count}}</div>
          <div class="text">头条</div>
        </div>
        <div class="data-item">
          <div class="conter">{{userInfo.follow_count}}</div>
          <div class="text">关注</div>
        </div>
        <div class="data-item">
          <div class="conter">{{userInfo.follow_count}}</div>
          <div class="text">粉丝</div>
        </div>
        <div class="data-item">
          <div class="conter">{{userInfo.like_count}}</div>
          <div class="text">获赞</div>
        </div>
      </div>

    </div>
    <!-- 未登录头部 -->
    <div class="header not-login" v-else>
      <div class="login-btn" @click="$router.push('/login')">
        <div class="mobile">
          <img src="~@/assets/mobile.png" alt="" />
        </div>
        <div class="text">登录/注册</div>
      </div>
    </div>

    <!-- 宫格导航 -->
      <van-grid :column-num="2" class="my-grid" clickable>
        <van-grid-item class="grid-item">
          <div slot="icon" class="iconfont icon-shoucang"></div>
          <div slot="text" class="text">收藏</div>
        </van-grid-item>
        <van-grid-item class="grid-item" clickable>
          <div slot="icon" class="iconfont icon-lishi"></div>
          <div slot="text" class="text">历史</div>
        </van-grid-item>
      </van-grid>
      <!-- 消息通知模块 -->
      <div class="tzinfo">
        <van-cell title="消息通知" is-link />
        <van-cell title="小智同学" is-link />
      </div>
      <van-cell v-if="this.user" title="退出登录" class="loginout" clickable @click="loginOut"/>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { getUserInfo } from '@/api/user'
export default {
  name: 'My',
  components: {},
  props: {},
  data () {
    return {
      userInfo: {}
    }
  },
  created () {
    if (this.user) {
      this.getUserInfo()
    }
  },
  mounted () {},
  methods: {
    async getUserInfo () {
      try {
        const { data } = await getUserInfo()
        this.userInfo = data.data
        console.log(this.userInfo)
      } catch (error) {
        this.$toast('获取用户数据列表失败')
      }
    },
    loginOut () {
      this.$store.commit('setUser', null)
    }
  },
  computed: {
    ...mapState(['user'])
  }
}
</script>

<style scoped lang="less">
.my-container {
  .header {
    width: 100%;
    height: 361px;
    background-image: url('~@/assets/banner.png');
    background-size: cover;
  }
  .not-login {
    display: flex;
    justify-content: center;
    align-items: center;
    .login-btn {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      .mobile {
        width: 132px;
        height: 132px;
        margin-bottom: 15px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .text {
        font-size: 28px;
        color: #fff;
      }
    }
  }
  .userinfo {
    box-sizing: border-box;
    padding: 76px 32px 23px;
    .base-info {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .left {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .userinfo-img {
          width: 150px;
          height: 150px;
          border: 1px solid #fff;
          margin-right: 22px;
        }
        .text {
          color: #fff;
          font-size: 30px;
        }
      }
      .right {
        .editUserInfo {
          width: 116px;
          height: 33px;
          font-size: 20px;
        }
      }
    }
  }
  .status-info {
    height: 130px;
    display: flex;
    .data-item {
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      .conter {
        color: #fff;
        font-size: 36px;
      }
      .text {
        color: #fff;
        font-size: 23px;
      }
    }
  }
  .my-grid{
    .grid-item{
      .icon-shoucang{
        color:  #eb5253;

      }
      .icon-lishi{
        color: #ff9d1d;
      }
      .iconfont{
        font-size: 45px;
      }
      .text{
        font-size: 28px;
      }
    }
  }
  .tzinfo{
    margin: 15px 0;
    font-size: 30px;
  }
  .loginout{
    text-align: center;
    font-size: 30px;
  }
}
</style>
